#include <stdio.h>
#include <stdlib.h>

#include "CMyString.h"
#include "MyString.h"

CLyfString::CLyfString()
{
	m_pString = NULL;
	m_nLen = 0;
}

CLyfString::CLyfString(const char* pStr)
{
	m_nLen = LyfStrLen(pStr);
	m_pString = new char[m_nLen];
	LyfStrCpy(m_pString, pStr);
}

CLyfString::CLyfString(CLyfString& strObj)
{
	m_nLen = strObj.m_nLen;
	m_pString = new char[m_nLen];
	LyfStrCpy(m_pString, strObj.c_str());
}

CLyfString::~CLyfString()
{
	if (NULL != m_pString)
	{
		delete [] m_pString;
	}

	m_pString = NULL;
	m_nLen = 0;
}

char* CLyfString::c_str() const
{
	int nLen = LyfStrLen(m_pString);
	return m_pString;
}

int CLyfString::length()
{
	return m_nLen;
}

int CLyfString::compare(const char* pStr)
{
	return LyfStrCmp(m_pString, pStr);
}

int CLyfString::compare(const CLyfString strObj)
{
	return LyfStrCmp(m_pString, strObj.c_str());
}

CLyfString& CLyfString::operator+(const char* pStr)
{
	CLyfString* pStrTemp = new CLyfString(m_pString);
	*pStrTemp += pStr;

	return *pStrTemp;
}

CLyfString& CLyfString::operator+(const CLyfString strObj)
{
	return (*this+strObj.c_str());
}

void CLyfString::operator=(const char* pStr)
{
	if (NULL != m_pString)
	{
		delete [] m_pString;
		m_pString = NULL;
	}

	m_nLen = LyfStrLen(pStr);
	m_pString = new char[m_nLen];
	LyfStrCpy(m_pString, pStr);
}

void CLyfString::operator=(const CLyfString strObj)
{
	*this = strObj.c_str();
}

void CLyfString::operator+=(const char* pStr)
{
	m_pString = LyfStrCat(m_pString, pStr);
	m_nLen = m_nLen + LyfStrLen(pStr) - 1;
}

void CLyfString::operator+=(const CLyfString strObj)
{
	*this += strObj.c_str();
}

bool CLyfString::operator==(const char* pStr)
{
	if (0 == compare(pStr))
	{
		return true;
	}

	return false;
}

bool CLyfString::operator==(const CLyfString strObj)
{
	return (*this == strObj.c_str());
}

CLyfString operator+(const char* pStr, CLyfString strObj)
{
	return (strObj + pStr);
}

bool operator==(const char* pStr, CLyfString strObj)
{
	return (strObj == pStr);
}
